//
//  CZQHomeController.m
//  weibo
//
//  Created by Apple on 15-1-29.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "CZQHomeController.h"
#import "CZQScanController.h"
#import "CZQTitleBtn.h"
#import "CZQPopMenuView.h"
#import "CZTestTableViewController.h"

@interface CZQHomeController ()
/**
 *  默认视图
 */
@property (nonatomic, weak) CZQDefaultView *defaultView;
@end

@implementation CZQHomeController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // 1.初始化导航条
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem BarButtomItemWithNorImage:@"navigationbar_friendsearch"  SelImage:@"navigationbar_friendsearch_highlighted"  target:self action:@selector(friendsearch)];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem BarButtomItemWithNorImage:@"navigationbar_pop"  SelImage:@"navigationbar_pop_highlighted"  target:self action:@selector(scan)];
    
    
    //创建一个自定义的标题按钮
    CZQTitleBtn *btn = [[CZQTitleBtn alloc] init];
//    self.navigationItem.titleView = btn;

    [btn setTitle:@"首页" forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"navigationbar_arrow_up"] forState:UIControlStateSelected];
    [btn sizeToFit];
    
    //增加点击事件
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.titleView = btn;
    
    
    // 2.初始化默认界面
    self.defaultCenterView.iconImageName = @"visitordiscover_feed_image_house";
    self.defaultCenterView.info = @"当你关注一些人以后，他们发布的最新消息会显示在这里";
    
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
   
    // 开始旋转
    [self.defaultView startRotate];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
   
    // 停止旋转
    [self.defaultView stopRotate];
}

- (void)btnClick:(CZQTitleBtn *)titleBtn{
    titleBtn.selected = !titleBtn.selected;
    // 需要显示内容
    CZTestTableViewController *testVc = [[CZTestTableViewController alloc] init];
    testVc.view.size = CGSizeMake(150, 200);
    [CZQPopMenuView popFrom:titleBtn contentVC:testVc dismiss:^{
        titleBtn.selected = !titleBtn.selected;
    }];
    
}


- (void)friendsearch{
    
    NSLog(@"-----");

}

- (void)scan{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Scan" bundle:nil];
    CZQScanController *scanVc = [sb instantiateInitialViewController];
    
    [self presentViewController:scanVc animated:YES completion:nil];
}

@end
